package com.atguigu.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/8/7
 * @desc 两个普通同步方法，1部手机，先发邮件还是发短信？
 */
public class Lock1Demo {
    public static void main(String[] args) throws InterruptedException {
        Phone phone1 = new Phone();
        new Thread(phone1::sendEmail, "t1").start();
        // 保证 t1 先启动
        TimeUnit.MILLISECONDS.sleep(100);
        new Thread(phone1::sendSMS, "t2").start();
    }

    private static class Phone {
        /**
         * 普通同步方法
         */
        public synchronized void sendEmail() {
            System.out.println("-----Email");

        }

        public synchronized void sendSMS() {
            System.out.println("-----SMS");
        }
    }

}

